package Data_base;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class TestJDBC {
    public static void main(String[] args) throws Exception {
        String driver = "com.mysql.jdbc.Driver";
        String path = "jdbc:mysql://localhost:3306/test1";
        String username = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(path, username, password);
        System.out.println("连接成功");
        System.out.println("请输入用户名:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入密码:");
        String pwd = sc.nextLine();
        String sql1 = "select * from admin where name='"+name+"' and pwd ='"+pwd+"'";
        String sql = "insert into admin(`name`,`pwd`) VALUES ('" + name + "','" + pwd + "')";
//        System.out.println(sql);
        Statement state = conn.createStatement();
//        int r = state.executeUpdate(sql);
//        if (r > 0) {
//            System.out.println("新增注册成功");
//        }else {
//            System.out.println("注册失败");
//        }
//        System.out.println(r);
        ResultSet res = state.executeQuery(sql1);
        System.out.println(sql1);
//        res.next();
        if (res.next()){
//            int id = res.getInt("id");
//            String n = res.getString("name");
//            String p = res.getString("pwd");
//            System.out.println("id:"+id);
//            System.out.println("name:"+n);
//            System.out.println("pwd:"+p);
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
        res.close();
        state.close();
        conn.close();
    }
}
